/*
 * @Author: weidewei
 * @Date: 2025-05-19 09:09:42
 * @LastEditors: weidewei
 * @LastEditTime: 2025-05-21 18:25:49
 * @Description: 
 * @FilePath: \v3\src\main.ts
 */
import { createApp } from "vue";
import App from "./App.vue";
import VueRouter from "./router/index";
import { createPinia  } from "pinia";
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate';
import http from '@/utils/http';
import 'element-plus/dist/index.css';
const app = createApp(App);
const pinia = createPinia()
app.config.errorHandler = (err, instance, info) => {
  // 全局捕获异常
  //   console.log(info)
};
// 注册全局事件总线
app.config.globalProperties.$bus = {
  events: {},
  emit(event: any, ...args: any) {
    (this.events[event] || []).forEach((fn: any) => fn(...args));
  },
  on(event:any, cb:any) {
    if (!this.events[event]) this.events[event] = [];
    this.events[event].push(cb);
  },
  off(event:any, cb:any) {
    if (!this.events[event]) return
    this.events[event] = this.events[event].filter((fn:any) => fn !== cb)
  }
};
app.config.globalProperties.$http = http;
pinia.use(piniaPluginPersistedstate); 
app.use(pinia);
app.use(VueRouter);
app.mount("#app");
